package com.hy.hongying.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hy.hongying.bo.VideoMyselfBo;
import com.hy.hongying.entity.Coins;
import com.hy.hongying.entity.Video;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VideoDao extends BaseMapper<Video> {
    @Select("SELECT o.preurl url,v.id,v.ctime,v.info,v.title FROM t_oss o INNER JOIN t_video v ON v.oid=o.id\n" +
            "WHERE v.uid=${uid} AND v.flag=1 ORDER BY v.ctime DESC")
    List<VideoMyselfBo> myVideo(@Param("uid")Integer uid);
    /*
    选择有类型的
     */
    @Select("SELECT o.preurl url,v.id,v.ctime,v.info,v.title FROM t_oss o INNER JOIN t_video v ON v.oid=o.id\n" +
            "WHERE v.type=#{type} AND v.flag=1 ORDER  BY RAND() LIMIT 0,3")
    List<VideoMyselfBo> watchVideoType(@Param("type")Integer type);
    /*
    选择无类型的
     */
    @Select("SELECT o.preurl url,v.id,v.ctime,v.info,v.title FROM t_oss o INNER JOIN t_video v ON v.oid=o.id\n" +
            "WHERE v.flag=1 ORDER BY RAND() LIMIT 0,3")
    List<VideoMyselfBo> watchVideoNoType();

    @Update("update t_video set flag=2 where oid=${oid}")
    int update(@Param("oid")Integer oid);
    /*
   模糊查询的类型
    */
    @Select("SELECT o.preurl url,v.id,v.ctime,v.info,v.title FROM t_oss o INNER JOIN t_video v ON v.oid=o.id\n" +
            "WHERE v.flag=1 and title like '%${title}%'ORDER  BY RAND() LIMIT 0,3")
    List<VideoMyselfBo> watchVideoTypes(@Param("title")String title);
    /*
    给用户视频投币完成交易
     */
    @Select("select integral from t_wallet where uid=${uid}")
    int selectUserIntegral(@Param("uid")Integer uid);//查询金额
    @Update("UPDATE t_wallet set integral=integral-${count} WHERE uid=${uid}")
    int updateUserIntegral01(@Param("count")Integer count,@Param("uid")Integer uid);//扣取
    @Update("UPDATE t_wallet set integral=integral+${count} WHERE uid=${uid}")
    int updateUserIntegral02(@Param("count")Integer count,@Param("uid")Integer uid);//添加
    @Insert("insert t_coins(oid,count,uid) values(${oid},${count},${uid})")
    int insertCoins(Coins coins);//添加历史
    @Select("SELECT SUM(count) FROM t_coins WHERE oid=${oid}")
    int selectAllOssCoins(@Param("oid")Integer oid);//返回总数量


}
